﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services;
using System.ComponentModel;

namespace Billing.PaymentServices
{
    [WebService(Namespace = "http://Billing/Services/2008/08", Name = "AuthenticationService")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class AuthenticationService : IAuthenticationService
    {
        private Guid SalaroRightID = new Guid("5ee7f7f3-f81d-4f4c-84f0-c768adc608f5");

        Billing.Services.BillingSoapHeader billingSoapHeader;
        public Billing.Services.BillingSoapHeader BillingSoapHeader
        {
            get
            {
                return this.billingSoapHeader;
            }
            set
            {
                this.billingSoapHeader = value;
            }
        }

        public void Authenticate(string userName, string password, int? versionMajor, int? versionMinor, int? versionBuild, int? versionRevision, ref int? userID, ref int? departmentID, ref Guid? sessionGUID, ref Guid? userGUID, ref string userFullName, ref int? result)
        {
            Billing.DataObjects.ShellDataContext context = new Billing.DataObjects.ShellDataContext();

            context.UserLogOn(userName, password, versionMajor, versionMinor, versionBuild, versionRevision, ref userID, ref departmentID, ref sessionGUID, ref userGUID, ref userFullName, ref result);

            Billing.DataObjects.BillingDataContext context2 = new Billing.DataObjects.BillingDataContext();
            if (result == 0)
            {
                context.RelationExists(userGUID, SalaroRightID, ref result);
                if (result == 0)
                    context2.PaymentPointShiftOpen(userName, Convert.ToInt16(BillingSoapHeader.PaymentPointID));
            }
        }

        public void ChangeUserPassword(int? userID, string oldPassword, string newPassword, ref bool? result)
        {
            Billing.DataObjects.ShellDataContext context = new Billing.DataObjects.ShellDataContext();
            context.ChangeUserPassword(userID, oldPassword, newPassword, ref result);
        }
    }
}
